package com.sgb.kjwl.view.ui.activity.self.websiteManage;

import android.content.Context;
import android.content.Intent;
import androidx.databinding.DataBindingUtil;
import androidx.recyclerview.widget.GridLayoutManager;

import com.sgb.kjwl.AppActivity;
import com.sgb.kjwl.R;
import com.sgb.kjwl.databinding.ActivityWebsiteQuality3Binding;
import com.sgb.kjwl.di.self.DaggerSelfComponent;
import com.sgb.kjwl.di.self.SelfModule;
import com.sgb.kjwl.model.entity.self.WebsiteQualityEntity;
import com.sgb.kjwl.view.ui.adapter.self.website.WebsiteQualityAdapter3;
import com.sgb.kjwl.viewmodel.self.website.WebsiteRequalityModel3;
import com.swgk.core.base.di.AppComponent;
import com.swgk.core.recyclerview.adapter.AdapterOnItemClick;

import java.util.List;

import javax.inject.Inject;

public class WebsiteQualifiActivity3 extends AppActivity {

    private ActivityWebsiteQuality3Binding binding;
    private WebsiteQualityAdapter3 adapter;
    private String companyId = "";

    @Inject
    WebsiteRequalityModel3 qualityModel;

    public static void start(Context context,String id){
        Intent intent = new Intent(context, WebsiteQualifiActivity3.class);
        intent.putExtra("companyId",id);
        context.startActivity(intent);
    }

    @Override
    protected void setupActivityComponent(AppComponent appComponent) {
        DaggerSelfComponent.builder()
                .appComponent(appComponent)
                .selfModule(new SelfModule(this))
                .build()
                .inject(this);
    }

    @Override
    protected void initView() {
        binding = DataBindingUtil.setContentView(this, R.layout.activity_website_quality3);
        binding.include.ivBack.setOnClickListener(view -> finish());
        binding.include.titleView.setText("企业资质");
        binding.include.rightView.setText("上传资质");
        binding.include.rightView.setOnClickListener(view -> {
            WebsiteQualityUploadImgActivity3.start(WebsiteQualifiActivity3.this,null,companyId);
        });

        GridLayoutManager layoutmanager = new GridLayoutManager(this,2);
        binding.listView.setLayoutManager(layoutmanager);

        adapter = new WebsiteQualityAdapter3(this,null);
        binding.listView.setAdapter(adapter);

        adapter.setOnItemClick(new AdapterOnItemClick<WebsiteQualityEntity>() {
            @Override
            public void onItemClick(WebsiteQualityEntity goodsInfoEntity3, int position) {
                WebsiteQualityUploadImgActivity3.start(WebsiteQualifiActivity3.this,goodsInfoEntity3,companyId);
            }
        });
    }

    @Override
    protected void init() {
        companyId = getIntent().getStringExtra("companyId");
    }

    @Override
    protected void onResume() {
        super.onResume();
        qualityModel.getQualityListData(companyId);
    }

    public void showQualityList(List<WebsiteQualityEntity> list){
        adapter.setDatas(list);
    }
}
